package fw.asmx.launcher.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import fw.asmx.launcher.R;
import fw.asmx.launcher.adapter.item.AppItem;

import java.util.List;

public class AppListAdapter extends ArrayAdapter<AppItem>
{
    private int res;
    public AppListAdapter(Context context, int resource,
                          List<AppItem> objects)
    {
        super(context, resource, objects);
        this.res=resource;
    }

    @Override public View getView(int pos, View cv, ViewGroup parent)
    {
        RelativeLayout rl;
        if(cv==null)
        {
            rl=new RelativeLayout(getContext());
            LayoutInflater li=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            li.inflate(res,rl,true);
        }
        else
        {
            rl=(RelativeLayout)cv;
        }

        AppItem ai=getItem(pos);

        ImageView iv=(ImageView)rl.findViewById(R.id.iv_app_icon);
        TextView tv=(TextView)rl.findViewById(R.id.tv_app_name);
        iv.setImageDrawable(ai.getIcon());
        tv.setText(ai.getAppName());

        return rl;
    }
}
